#define _CRT_SECURE_NO_WARNINGS	

#include <stdio.h>
#include<stdbool.h>

bool Check(int x)
{
    int sum = x * x;
    if (sum % 10 == x || sum % 100 == x || sum % 1000 == x || sum % 10000 == x || sum % 100000 == x || sum % 1000000 == x || sum % 10000000 == x || sum % 100000000 == x)
        return true;
    return false;
}

int main()
{
    int n;
    scanf("%d", &n);
    int count = 0;
    for (int i = 0; i <= n; i++)
    {
        if (Check((i)))
            count++;
    }
    printf("%d\n", count);
}